               
var ADViewer;
var node_id = "";
pid = $.cookie('getPid');
$(function () {
	 clearInput();
	 //cll 显示按钮
	$("#start_1").children().css({"pointer-events":"","color":"#000"});

	var b123="<div style='height: 160px;'></div>";
	$("#media").append(b123);
	b123=i18n("i18n-lan-media");
	$("#media").find(".form-group").find("label").first().text(b123);
    //点击验证按钮,获取页面XML文本
    // $("#Validate").click(function () {

    //     xmlcontentvalue = saveAllPartInfo();
    //     //dmodule = hasdmodule_catalog();
    // });

    //自动加载验证页面
	// cll
    function initvalidateHtml() {
		xmlcontentvalue = saveAllPartInfo();
		//dmodule = hasdmodule_catalog();
//        var validateURL = "component/ValidateXML.html";
//        // if (document.getElementById("validateShow") != null) {
//            document.getElementById("validateShow").innerHTML = "<object type='text/html' data='" + validateURL + "' height='68%' width='100%'></object>";
//        // }
    }

//	cll 加载验证xml数据loading页面
	$("#Validate").click(function(){
		var validateURL = "component/ValidateXML.html";
		// if(document.getElementById("validateShow") != null) {
			document.getElementById("validateShow").innerHTML = "<object type='text/html' data='" + validateURL + "' height='68%' width='100%'></object>";
		// }
	})

	// cll 检验XML数据验证modal show时
	$('#validate-modal').on('shown.bs.modal', function () {
	  initvalidateHtml();
	})

    // initvalidateHtml();

    $("#productxml").click(function () {
        $("#note").addClass("hide");
        $("#media").removeClass("hide");
        //		initMedia();
        media();
        $("#left").hide();
    });

    $("#savePartInfo").click(function () {
        saveXML(saveAllPartInfo());
    });

    //addProShow();

    showAndHideSetMedia();



});

//显示隐藏设置多媒体
function showAndHideSetMedia(){
	if($(".figure").find(".title").first().text()==="请设置多媒体(Unity3D)") {
    		$("#productxml").click();
    		$("#left").hide();
    		$("#cancel").hide();
//  		$("#media").removeClass("hide");
    	}else{
    		$("#left").show();
    		$("#cancel").show();
    		$("#media").addClass("hide");
    	}
}

////关闭专家视图
//function closePro(){
//	$("#left").show();
//	$("#proText").html("");
//	$("#proShowDiv").hide();
//
//}

function proShow(){
	$("#lbody").hide();
	var v1=saveAllPartInfo();
	var  dmodule = hasdmodule_catalog();
//		var saveXMLValue = eachDIVChild();
		var data = {
			dmodule: dmodule,
			sid: nowSid,
			pid: pid,
			xmlcontentvalue: v1,
			s1000dType: s1000dType
		};
		$.ajax({
			type: "POST",
			url: baseApi + "xml/creation/proShow",
			data: data,
			dataType: "JSON",
			success: function(r) {
				if(r.isSuccess) {
					var tt=r.data.split("\n");
					var html="";
					$.each(tt, function(i,t) {
						html="<div id=\"ptd"+i+"\"></div>";
						$("#proText").append(html);
						$("#ptd"+i).text(t);
					});
					$("#proShowDiv").show();
				} else {
					showTip("失败:"+define(r.msg), "");
				}
			}
		});
}

function editSelectedObject() {
    ADViewer = document.getElementById("ADViewer");
    if (ADViewer == null)
        return;

    var Objects = ADViewer.ECompositeViewer.Section.Content.Objects(1); //1 is to return selected objects
    if (Objects.Count >= 1) {
        var Props = Objects(1).Properties;
        for (p = 1;
             (p <= Props.Count); p++) {
            Prop = Props(p);
            if (Prop.Name == "ID") {
                if (Prop.Value != node_id) {
                    $("#nodeid").val(Prop.Value);
                    node_id = Prop.Value;
                    if (isExist(Prop.Value)) {
                        initPartInfo(Prop.Value);
                    }
                }
                break;
            }
        }
    }
}

function isExist(nodeId) {
    var lis = $(".li_class");
    var isExist = false;
    for (var i = 0; i < lis.length; i++) {
        if (nodeId && "li_" + nodeId == lis.eq(i).attr("id")) {
            isExist = true;
            break;
        }
    }
    return isExist;
}

function initPartInfo(nodeId) {
    $("#nodeid").val(nodeId);
    $("#quantityPerNextHigherAssy").val($("#quantityPerNextHigherAssy_" + nodeId).html());
    $("#manufacturerCode").val($("#manufacturerCode_" + nodeId).html()); //厂家代码
    $("#partNumber").val($("#partNumber_" + nodeId).html()); //部件型号
    $("#descrForPart").val($("#descrForPart_" + nodeId).html()); //部件描述
    $("#unitOfIssue").val($("#unitOfIssue_" + nodeId).html()); //单位
    $("#specialStorage").val($("#specialStorage_" + nodeId).html()); //特殊储存
    $("#reasonForSelection").val($("#reasonForSelection_" + nodeId).html()); //原因
    $("#physicalSecurityPilferageCode").val($("#physicalSecurityPilferageCode_" + nodeId).html());
    $("#descrForLocation").val($("#descrForLocation_" + nodeId).html()); //位置描述
    $("#service").val($("#service_" + nodeId).html());
    $("#sourceMaintRecoverability").val($("#sourceMaintRecoverability_" + nodeId).html());
}

//tws
$("#saveWrngdata").click(function(){
	savePartInfo();
})

//保存当前部件数据
function savePartInfo() {
    var nodeId = $("#nodeid").val();

    if (isExist(nodeId)) {
        editPartInfo(nodeId); //修改
    } else {
        addPartInfo(nodeId); //添加
    }
	clearInput();

	//tws
	$("#editTechInfo").modal("hide");
	$("#left").removeClass("hide");

}
function clearInput(){
	 $("#partNumber").val("");
    $("#unitOfIssue").val("");
    $("#descrForLocation").val("");
    $("#manufacturerCode").val("");
    $("#descrForPart").val("");
}
//添加
function addPartInfo(nodeId) {
    /*if(!ADViewer || !ADViewer.parentNode)
     return;*/
    var Unity = document.getElementById("UnityObject");
    var id = nodeId;

    //var id = ADViewer.parentNode.id+"-"+ADViewer.title+"-hot-"+nodeId;
    var quantityPerNextHigherAssy = $("#quantityPerNextHigherAssy").val();
    var manufacturerCode = $("#manufacturerCode").val(); //厂家代码
    var partNumber = $("#partNumber").val(); //部件型号
    var descrForPart = $("#descrForPart").val(); //部件描述
    var unitOfIssue = $("#unitOfIssue").val(); //单位
    var specialStorage = $("#specialStorage").val(); //特殊储存
    var reasonForSelection = $("#reasonForSelection").val(); //原因
    var physicalSecurityPilferageCode = $("#physicalSecurityPilferageCode").val();
    var descrForLocation = $("#descrForLocation").val(); //位置描述
    var service = $("#service").val();
    var sourceMaintRecoverability = $("#sourceMaintRecoverability").val();

    var li = "";
    if (!nodeId || nodeId == "") {
        alert(i18n("i18n-alert-nodeId"));
        return;
    } else {
        li += "<div id=\"li_" + nodeId + "\" class=\"li_class\">";
    }

    if (!partNumber || partNumber == "") {
        alert(i18n("i18n-alert-partNumber"));
        return;
    } else {
        li += "<a name=\"internalRef\" onClick=\"msgToUnity('" + id + "')\" id=\"Link_" + id + "\" href=\"#\">" + partNumber + "</a>";
    }

    li += "<div class=\"catalogSeqNumber \" id=\"catalog_" + id + "\">";
    if (!manufacturerCode || manufacturerCode == "") {
        li += "<div class='hide'>+"+i18n("i18n-lan-manufacturerCode")+"+<span id='manufacturerCode_" + nodeId + "' >" + manufacturerCode + "</span></div>";
    } else {
        li += "<div>+"+i18n("i18n-lan-manufacturerCode")+"<span id='manufacturerCode_" + nodeId + "'>" + manufacturerCode + "</span></div>";
    }

    li += "<div>+"+i18n("i18n-lan-partNumber")+"<span class='partNumber' id='partNumber_" + nodeId + "'>" + partNumber + "</span></div>";
    li += "<div>";
    if (!descrForPart || descrForPart == "") {
        //
        li += "<div class='hide'>"+i18n("i18n-lan-descrForPart")+"<span id='descrForPart_" + nodeId + "'>" + descrForPart + "</span></div>";
    } else {
        li += "<div>"+i18n("i18n-lan-descrForPart")+"<span id='descrForPart_" + nodeId + "'>" + descrForPart + "</span></div>";
    }
    if (!unitOfIssue || unitOfIssue == "") {
        //
        li += "<div class='hide'>"+i18n("i18n-lan-unitOfIssue")+"<span id='unitOfIssue_" + nodeId + "'>" + unitOfIssue + "</span></div>";
    } else {
        li += "<div>"+i18n("i18n-lan-unitOfIssue")+"<span id='unitOfIssue_" + nodeId + "'>" + unitOfIssue + "</span></div>";
    }
    if (!reasonForSelection || reasonForSelection == "") {
        //
        li += "<div class='hide'>"+i18n("i18n-lan-specialStorage")+"<span id='specialStorage_" + nodeId + "'>" + specialStorage + "</span>";
    } else {
        li += "<div>"+i18n("i18n-lan-specialStorage")+"<span id='specialStorage_" + nodeId + "'>" + specialStorage + "</span>";
    }
    if (!reasonForSelection || reasonForSelection == "") {
        //
        li += "<span class='hide'>（"+i18n("i18n-lan-reasonForSelection")+"<span id='reasonForSelection_" + nodeId + "'>" + reasonForSelection + "</span>）</span>";
    } else {
        li += "<span>("+i18n("i18n-lan-reasonForSelection")+"<span id='reasonForSelection_" + nodeId + "'>" + reasonForSelection + "</span>)</span>";
    }
    li += "</div>";
    li += "</div>";
    if (!descrForLocation || descrForLocation == "") {
        //
        li += "<div class='hide'>"+i18n("i18n-lan-descrForLocation")+"<span id='descrForLocation_" + nodeId + "'>" + descrForLocation + "</span></div>";
    } else {
        li += "<div>"+i18n("i18n-lan-descrForLocation")+"<span id='descrForLocation_" + nodeId + "'>" + descrForLocation + "</span></div>";
    }
    if (!quantityPerNextHigherAssy || quantityPerNextHigherAssy == "") {
        //
        li += "<div class='hide'>quantityPerNextHigherAssy:<span id='quantityPerNextHigherAssy_" + nodeId + "'>" + quantityPerNextHigherAssy + "</span></div>";
    } else {
        li += "<div>quantityPerNextHigherAssy:<span id='quantityPerNextHigherAssy_" + nodeId + "'>" + quantityPerNextHigherAssy + "</span></div>";
    }
    if (!physicalSecurityPilferageCode || physicalSecurityPilferageCode == "") {
        //
        li += "<div class='hide'>physicalSecurityPilferageCode:<span id='physicalSecurityPilferageCode_" + nodeId + "'>" + physicalSecurityPilferageCode + "</span></div>";
    } else {
        li += "<div>physicalSecurityPilferageCode:<span id='physicalSecurityPilferageCode_" + nodeId + "'>" + physicalSecurityPilferageCode + "</span></div>";
    }
    if (!service || service == "") {
        //
        li += "<div class='hide'>service:<span id='service_" + nodeId + "'>" + service + "</span></div>";
    } else {
        li += "<div>service:<span id='service_" + nodeId + "'>" + service + "</span></div>";
    }
    if (!sourceMaintRecoverability || sourceMaintRecoverability == "") {
        //
        li += "<div class='hide'>sourceMaintRecoverability:<span id='sourceMaintRecoverability_" + nodeId + "'>" + sourceMaintRecoverability + "</span></div>";
    } else {
        li += "<div>sourceMaintRecoverability:<span id='sourceMaintRecoverability_" + nodeId + "'>" + sourceMaintRecoverability + "</span></div>";
    }
    li += "</div>";
    li += "</div>";

    $("#catalog_li").append(li);
    $("#right").append(li);
    showCatalogSeq(id);
}

//修改
function editPartInfo(nodeId) {
    //var id = ADViewer.parentNode.id+"-"+ADViewer.title+"-hot-"+nodeId;
    var id = nodeId;

    var quantityPerNextHigherAssy = $("#quantityPerNextHigherAssy").val();
    var manufacturerCode = $("#manufacturerCode").val(); //厂家代码
    var partNumber = $("#partNumber").val(); //部件型号
    var descrForPart = $("#descrForPart").val(); //部件描述
    var unitOfIssue = $("#unitOfIssue").val(); //单位
    var specialStorage = $("#specialStorage").val(); //特殊储存
    var reasonForSelection = $("#reasonForSelection").val(); //原因
    var physicalSecurityPilferageCode = $("#physicalSecurityPilferageCode").val();
    var descrForLocation = $("#descrForLocation").val(); //位置描述
    var service = $("#service").val();
    var sourceMaintRecoverability = $("#sourceMaintRecoverability").val();

    $("#Link_" + id).html(partNumber);
    $("#manufacturerCode_" + nodeId).html(manufacturerCode);
    $("#partNumber_" + nodeId).html(partNumber);
    $("#descrForPart_" + nodeId).html(descrForPart);
    $("#unitOfIssue_" + nodeId).html(unitOfIssue);
    $("#specialStorage_" + nodeId).html(specialStorage);
    $("#reasonForSelection_" + nodeId).html(reasonForSelection);
    $("#descrForLocation_" + nodeId).html(descrForLocation);
    $("#quantityPerNextHigherAssy_" + nodeId).html(quantityPerNextHigherAssy);
    $("#physicalSecurityPilferageCode_" + nodeId).html(physicalSecurityPilferageCode);
    $("#service_" + nodeId).html(service);
    $("#sourceMaintRecoverability_" + nodeId).html(sourceMaintRecoverability);

    if ($("#manufacturerCode_" + nodeId).html() != "" && $("#manufacturerCode_" + nodeId).hasClass("hide")) {
        //$("#"+nodeId+"_manufacturerCode").removeClass("hide");	//在 IE11 无效
        document.getElementById("manufacturerCode_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#manufacturerCode_" + nodeId).html() == "" && !$("#manufacturerCode_" + nodeId).hasClass("hide")) {
        document.getElementById("manufacturerCode_" + nodeId).parentNode.classList.add("hide");
    }
    if ($("#partNumber_" + nodeId).html() != "" && $("#partNumber_" + nodeId).hasClass("hide")) {
        document.getElementById("partNumber_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#partNumber_" + nodeId).html() == "" && !$("#partNumber_" + nodeId).hasClass("hide")) {
        document.getElementById("partNumber_" + nodeId).parentNode.classList.add("hide");
    }
    if ($("#descrForPart_" + nodeId).html() != "" && $("#descrForPart_" + nodeId).hasClass("hide")) {
        document.getElementById("descrForPart_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#descrForPart_" + nodeId).html() == "" && !$("#descrForPart_" + nodeId).hasClass("hide")) {
        document.getElementById("descrForPart_" + nodeId).parentNode.classList.add("hide");
    }
    if ($("#unitOfIssue_" + nodeId).html() != "" && $("#unitOfIssue_" + nodeId).hasClass("hide")) {
        document.getElementById("unitOfIssue_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#unitOfIssue_" + nodeId).html() == "" && !$("#unitOfIssue_" + nodeId).hasClass("hide")) {
        document.getElementById("unitOfIssue_" + nodeId).parentNode.classList.add("hide");
    }
    if ($("#specialStorage_" + nodeId).html() != "" && $("#specialStorage_" + nodeId).hasClass("hide")) {
        document.getElementById("specialStorage_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#specialStorage_" + nodeId).html() == "" && !$("#specialStorage_" + nodeId).hasClass("hide")) {
        document.getElementById("specialStorage_" + nodeId).parentNode.classList.add("hide");
    }
    if ($("#reasonForSelection_" + nodeId).html() != "" && $("#reasonForSelection_" + nodeId).hasClass("hide")) {
        document.getElementById("reasonForSelection_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#reasonForSelection_" + nodeId).html() == "" && !$("#reasonForSelection_" + nodeId).hasClass("hide")) {
        document.getElementById("reasonForSelection_" + nodeId).parentNode.classList.add("hide");
    }
    if ($("#descrForLocation_" + nodeId).html() != "") {
        document.getElementById("descrForLocation_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#descrForLocation_" + nodeId).html() == "" && !$("#descrForLocation_" + nodeId).hasClass("hide")) {
        document.getElementById("descrForLocation_" + nodeId).parentNode.classList.add("hide");
    }
    if ($("#quantityPerNextHigherAssy_" + nodeId).html() != "" && $("#quantityPerNextHigherAssy_" + nodeId).hasClass("hide")) {
        document.getElementById("quantityPerNextHigherAssy_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#quantityPerNextHigherAssy_" + nodeId).html() == "" && !$("#quantityPerNextHigherAssy_" + nodeId).hasClass("hide")) {
        document.getElementById("quantityPerNextHigherAssy_" + nodeId).parentNode.classList.add("hide");
    }
    if ($("#physicalSecurityPilferageCode_" + nodeId).html() != "" && $("#physicalSecurityPilferageCode_" + nodeId).hasClass("hide")) {
        document.getElementById("physicalSecurityPilferageCode_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#physicalSecurityPilferageCode_" + nodeId).html() == "" && !$("#physicalSecurityPilferageCode_" + nodeId).hasClass("hide")) {
        document.getElementById("physicalSecurityPilferageCode_" + nodeId).parentNode.classList.add("hide");
    }
    if ($("#service_" + nodeId).html() != "" && $("#service_" + nodeId).hasClass("hide")) {
        document.getElementById("service_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#service_" + nodeId).html() == "" && !$("#service_" + nodeId).hasClass("hide")) {
        document.getElementById("service_" + nodeId).parentNode.classList.add("hide");
    }
    if ($("#sourceMaintRecoverability_" + nodeId).html() != "" && $("#sourceMaintRecoverability_" + nodeId).hasClass("hide")) {
        document.getElementById("sourceMaintRecoverability_" + nodeId).parentNode.classList.remove("hide");
    } else if ($("#sourceMaintRecoverability_" + nodeId).html() == "" && !$("#sourceMaintRecoverability_" + nodeId).hasClass("hide")) {
        document.getElementById("sourceMaintRecoverability_" + nodeId).parentNode.classList.add("hide");
    }

}

//显示部件信息
function showCatalogSeq(id) {
    var seqId = "catalog_" + id;
    $(".catalogSeqNumber").each(function (i, item) {
        if (seqId == $(this).attr("id")) {
            if ($("#" + seqId).hasClass("hide"))
            //$("#catalog_"+id).removeClass("hide");	//在 IE11 无效
                document.getElementById(seqId).classList.remove("hide");
            //			else if(!$("#"+seqId).hasClass("hide"))
            //				//$("#catalog_"+id).addClass("hide");
            //				document.getElementById(seqId).classList.add("hide");
        } else if (!$(this).hasClass("hide")) {
            //$("#catalog_"+id).addClass("hide");
            document.getElementById($(this).attr("id")).classList.add("hide");
        }
    });
}

//删除当前部件数据
function removePartInfo() {
    var nodeId = $("#nodeid").val();
    if (nodeId && nodeId != "") {
        var li = $("#li_" + nodeId);
        if (li) {
            li.remove();
        }
    }
}

//保存所有数据,生成content信息内容
function saveAllPartInfo() {
    var lis = $(".li_class");
    var hotspotList = "";
    var catalogList = "";
    var content = "";

    var Unity = document.getElementById("UnityEmbed");
    if (Unity == null) {
        return;
    }
    if (lis.length > 0) {
        for (var i = 0; i < lis.length; i++) {
            var nodeId = "";
            var id = "";
            var quantityPerNextHigherAssy = "";
            var manufacturerCode = ""; //厂家代码
            var partNumber = ""; //部件型号
            var descrForPart = ""; //部件描述
            var unitOfIssue = ""; //单位
            var specialStorage = ""; //特殊储存
            var reasonForSelection = ""; //原因
            var physicalSecurityPilferageCode = "";
            var descrForLocation = ""; //位置描述
            var service = "";
            var sourceMaintRecoverability = "";

            nodeId = lis.eq(i).attr("id");
            nodeId = nodeId.substring(nodeId.indexOf("_") + 1);
            //id = ADViewer.parentNode.id+"-"+ADViewer.title+"-hot-"+nodeId;
            id = Unity.parentNode.parentNode.id + "-" + Unity.title + "-hot-" + nodeId;
            quantityPerNextHigherAssy = $("#quantityPerNextHigherAssy_" + nodeId).html();
            manufacturerCode = $("#manufacturerCode_" + nodeId).html(); //厂家代码
            partNumber = $("#partNumber_" + nodeId).html(); //部件型号
            descrForPart = $("#descrForPart_" + nodeId).html(); //部件描述
            unitOfIssue = $("#unitOfIssue_" + nodeId).html(); //单位
            specialStorage = $("#specialStorage_" + nodeId).html(); //特殊储存
            reasonForSelection = $("#reasonForSelection_" + nodeId).html(); //原因
            physicalSecurityPilferageCode = $("#physicalSecurityPilferageCode_" + nodeId).html();
            descrForLocation = $("#descrForLocation_" + nodeId).html(); //位置描述
            service = $("#service_" + nodeId).html();
            sourceMaintRecoverability = $("#sourceMaintRecoverability_" + nodeId).html();

            hotspotList += "<hotspot id=\"" + id + "\" applicationStructureIdent=\"hot" + nodeId + "\" applicationStructureName=\"" + nodeId + "\" hotspotType=\"CALLOUT\" hotspotTitle=\"" + partNumber + "\" objectDescr=\"" + descrForPart + "\"/>";

            catalogList += "<catalogSeqNumber id='catalogSeqNumber_" + nodeId + "' catalogSeqNumberValue=\"D00000000A" + nodeId + " \" indenture=\"" + getNum(nodeId) + "\">\n";
            catalogList += "<internalRef internalRefId='catalogSeqNumber_" + nodeId + "' internalRefTargetType='hotspot' xlink:actuate='onRequest' xlink:show='replace' xlink:href='#" + id + "' />\n";
            catalogList += "<itemSequenceNumber itemSeqNumberValue=\"00A\">\n";
            catalogList += "<reasonForSelection id='reasonForSelection_" + nodeId + "'  reasonForSelectionValue=\"" + reasonForSelectionFn(reasonForSelection) + "\"/>\n";
            catalogList += "<quantityPerNextHigherAssy>" + quantityPerNextHigherAssy + "</quantityPerNextHigherAssy>\n";
            catalogList += "<manufacturerCode id='manufacturerCode_" + nodeId + "'>" + manufacturerCode + "</manufacturerCode>\n";
            catalogList += "<partNumber id='partNumber_" + nodeId + "'>" + partNumber + "</partNumber>\n";
            catalogList += "<partIdentSegment>\n";
            catalogList += "<descrForPart>" + descrForPart + "</descrForPart>\n";
            catalogList += "<unitOfIssue>" + unitOfIssue + "</unitOfIssue>\n";
            catalogList += "<specialStorage>" + specialStorageFn(specialStorage) + "</specialStorage>\n";
            catalogList += "</partIdentSegment>\n";
            catalogList += "<partLocationSegment>\n";
            catalogList += "<descrForLocation>" + descrForLocation + "</descrForLocation>\n";
            catalogList += "</partLocationSegment>\n";
            catalogList += "<locationRcmdSegment>\n";
            catalogList += "<locationRcmd>\n";
            catalogList += "<service>" + service + "</service>\n";
            catalogList += "<sourceMaintRecoverability>" + sourceMaintRecoverability + "</sourceMaintRecoverability>\n";
            catalogList += "</locationRcmd>\n";
            catalogList += "</locationRcmdSegment>\n";
            catalogList += "</itemSequenceNumber>\n";
            catalogList += "</catalogSeqNumber>\n";
        }
    }

    if (hotspotList != "" && catalogList != "") {
        content += "<illustratedPartsCatalog>";
        //		content += "<catalogSequence seqClass=\"col-md-6\">";
        //		content += "<figure id=\""+ADViewer.parentNode.id+"\">";
        content += "<figure id=\"" + Unity.parentNode.parentNode.id + "\">";
        content += "<title>" + $(".title").html() + "</title>";
        var fileName = '';
        var title = '';
        //		title = ADViewer.title;
        //		var value = ADViewer.firstChild.value;
        title = Unity.title;
        //		var value = Unity.firstChild.value;
        var value = document.getElementById("UnityObject").firstChild.value;
        fileName = value.substring(value.lastIndexOf("/") + 1, value.lastIndexOf("."));
        content += "<graphic xlink:type='simple' xlink:href='URN:S1000D:" + fileName + "' xlink:title='" + $(".title").html() + "' infoEntityIdent='" + fileName + "' >";
        content += hotspotList;
        content += "</graphic>";
        content += "</figure>";
        //		content += "</catalogSequence>";
        content += "<initialProvisioningProject initialProvisioningProjectNumber=\"KZ7771111\" initialProvisioningProjectNumberSubject=\"" + $(".title").html() + "\" fileIdent=\"s\"/>";
        //		content += "<catalogSequence seqClass=\"col-md-6\">";
        content += catalogList;
        //		content += "</catalogSequence>";
        content += "</illustratedPartsCatalog>";
    }
    return content;
    //saveXML(content);
}

//保存xml文本数据
function saveXML(content) {
    //var dmodule = "";
    var value = content;
    var data = {
        sid: nowSid,
        pid: pid,
        dmodule: dmodule,
        xmlcontentvalue: value,
        s1000dType: s1000dType
    };
    $.ajax({
        type: "POST",
        url: baseApi + "xml/creation/saveOneDatamodulecodeXmlFile",
        data: data,
        dataType: "JSON",
        success: function (r) {
            if (r.isSuccess) {
                showTip("保存数据模块成功!", "");
				//cll 保存数据模块后重新生成HTML页面并刷新
				flushHtml("illustratedPartsCatalog");
            } else {
                showTip("保存数据模块失败:" + define(r.msg), "");
            }
        }
    });
}

function specialStorageFn(sp) {
    if (sp == "是") {
        return 1;
    } else {
        return 0;
    }
}

function reasonForSelectionFn(re) {
    if (re == "非必要配件") {
        return 0;
    } else if (re == "磨损") {
        return 1;
    } else if (re == "维护损坏") {
        return 2;
    } else if (re == "丢失") {
        return 3;
    } else if (re == "震动") {
        return 4;
    } else if (re == "腐蚀") {
        return 5;
    } else if (re == "变质") {
        return 6;
    } else if (re == "极端温度") {
        return 7;
    } else if (re == "意外损坏（保险）") {
        return 8;
    } else if (re == "其它") {
        return 9;
    }
}

/******* for unity3d ******/

//设置多媒体
function initFile(mySrc, title) {

    //	var mySrc = "./illustrations/ChaiJie_NeiBu.unity3d";
    if (mySrc != null && mySrc != "") {
        var divObj = document.getElementById("left");
        var htmlCode = "<div class=\"figure\" align=\"center\" id=\"fig-0001\">";
        htmlCode += "<div class='title'>" + title + "</div>";
        htmlCode += "<div class='extand hide'>" + mySrc.split(".")[mySrc.split(".").length - 1] + "</div>";
        htmlCode += "<div class='graphic hide'>" + mySrc + "</div>";
        htmlCode += "<object id=\"UnityObject\" classid=\"clsid:444785F1-DE89-4295-863A-D46C3A781394\" title=\"gra-0001\" width=\"800\" height=\"600\" codebase=\"plugins/UnityWebPlayer.exe\">" +
            "<param name=\"src\" value=\"" + mySrc + "\" />" +
            "<a href=\"plugins/UnityWebPlayer.exe\"></a>" +
            "<embed id=\"UnityEmbed\" src=\"" + mySrc + "\" width=\"800\" height=\"600\" type=\"application/vnd.unity\" pluginspage=\"plugins/UnityWebPlayer.exe\" /></object>";
        htmlCode += "</div></div>";
        htmlCode += '<div id="note"><div style="color: red;font-weight: bold">备注:unity内部需提供双击某一部件回调函数(函数名称须为:MessageToIE)传递ID(ID须为数字，不支持中文或字母)参数,若浏览器没有安装unity播放插件，请点击下载unity播放插件按钮</div>';

        htmlCode += '<div><form id="downUnityWebPlayerFull" action="#" ><input type="hidden" value="UnityWebPlayerFull.exe" id="UnityWebPlayerFull" name="UnityWebPlayerFull"/><input type="submit" onclick="downUnityWebPlayerFull();" class="btn btn-primary" value="下载unity播放插件"/></form><div></div>';
        htmlCode += "<div style='height: 160px;'></div>";
        divObj.innerHTML = htmlCode;
    }
}

//点击某一部件时回调此函数
function MessageToIE(msg) {
    clearInput();
    $("#nodeid").val(msg);
    if (isExist(msg)) {
        showCatalogSeq(msg);
        initPartInfo(msg);
    }
}

//双向通讯？？？？
function msgToUnity(name) {
    //	catalogSeqNumber_0003
    //	name = name.split("catalogSeqNumber_")[1];
    try {
        document.getElementById("UnityObject").SendMessage("Main Camera", "SelectByName", name)
    } catch (e) {
        try {
            document.getElementById("UnityEmbed").SendMessage("Main Camera", "SelectByName", name)
        } catch (e) {
            console.warn(e);
        }
    }
    if (isExist(name)) {
        showCatalogSeq(name);
        initPartInfo(name);
    }

	$("#removePartInfo").css({"pointer-events":"","color":"#000"});
}

//function changeToId(name) {
//	if(name == "电源") {
//		return "0001";
//	} else if(name == "主板") {
//		return "0002";
//	} else if(name == "显卡") {
//		return "0003";
//	} else if(name == "内存") {
//		return "0004";
//	} else if(name == "排风扇") {
//		return "0005";
//	} else if(name == "光驱") {
//		return "0006";
//	} else if(name == "硬盘") {
//		return "0007";
//	}
//}

//////////////////////////////////////////////////////
//打开弹窗
function initHtml(URL, id) {
    document.getElementById(id).innerHTML = "<embed type='text/html' src=" + URL + " height='68%' width='100%'></embed>";
}
//var mediaid=0;
//多媒体下拉列表加载
function initMedia() {
    var prama = {};
    //	prama.sid = window.parent.nowSid;
    prama.pid = $.cookie("getPid");
    var u = baseApi + 'media/fetchUnityListByPId';
    $.ajax({
        type: "GET",
        url: baseApi + 'media/fetchUnityListByPId',
        data: prama,
        dataType: "JSON",
        success: function (r) {
            window.parent.success(prama, u, r);
            if (r.isSuccess) {
                var h = "";
                for (i = 0; i < r.data.length; i++) {
                    h += "<option mediaid='" + r.data[i].mediaid + "' title='" + r.data[i].title + "' value='" + r.data[i].medianame + "." + r.data[i].fileformat + "'>" + r.data[i].title + "</option>";
                }
                $("#mediaID").html(h);
            } else {
                alert(r.msg, {
                    icon: 5
                });
            }
        },
        error: function (xhr, msg, errorThrown) {
            error(prama, u, xhr, msg, errorThrown);
            showTip("登陆验证过期,请重新登陆!");
        }
    });
}

//设置多媒体操作
function media() {
    initMedia();
    //取消按钮点击
    $("#cancel").click(function () {
        $('#media').addClass('hide');
        $("#note").removeClass("hide");
        $("#left").show();
    });
    //保存点击
    $("#signup").click(function () {
        initFile();
        var mySrc = "./illustrations/" + $("#mediaID").val().trim();
        var title = $("#mediaID").find("option:selected").attr("title");
        //添加连接到数据库
        addMediaLink($("#mediaID").find("option:selected").attr("mediaid"));

        initFile(mySrc, title);
        $('#media').addClass('hide');
        $("#right").html("");
        $("#partNumber").val("");
        $("#nodeid").val("");
        $("#descrForLocation").val("");
        $("#note").removeClass("hide");
        showAndHideSetMedia();
    });
}

function addMediaLink(id) {
		var patam = {
			sid: nowSid,
			pid: nowPid,
			dbid: nowDbid,
			mid: id,
			srand: nowSrand
		};
		var u = baseApi + "medialink/addMediaLink";
		$.ajax({
			type: "POST",
			data: patam,
			dataType: "json",
			url: u,
			success: function(r) {
				success(patam, u, r);
			},
			error: function(xhr, msg, errorThrown) {
				error(patam, u, xhr, msg, errorThrown);
				showTip(msg);
			}
		});
	}

//xml文件头部多媒体声明
function hasdmodule_catalog() {
    dmodule = "";
    var tar = $("#lbody").find('*');
    tar.each(function () {
        if ($(this).attr('class') === 'figure') {
            dmodule = figureM($(this), dmodule);
        }

    });
    return dmodule;
}

function figureM(tar, dmodule) {
    var extand = tar.find(".extand").text().trim();
    var graphic = tar.find(".graphic").text().trim();
    var str = graphic.split("/")[graphic.split("/").length - 1];
    str = str.split(".")[0];
    dmodule += "<!NOTATION " + extand + " PUBLIC '-//USA-DOD//NOTATION Computer Graphics Metafile//EN'>\n";
    dmodule += "<!ENTITY " + str + " SYSTEM '" + graphic + "' NDATA " + extand + ">\n";

    return dmodule;
}

function downUnityWebPlayerFull() {
    $("#downUnityWebPlayerFull").attr("action", baseApi + "qa/downFile");
}


window.onload = function () {
    var mySrc = $("#left").find("param").val();
    var htmlCode = "<div class='extand hide'>" + mySrc.split(".")[mySrc.split(".").length - 1] + "</div>";
    htmlCode += "<div class='graphic hide'>" + mySrc + "</div>";

    $("#left").find(".figure").append(htmlCode);
   var html = '<div id="note"><div style="color: red;font-weight: bold">备注:unity内部需提供双击某一部件回调函数(函数名称须为:MessageToIE)传递ID(ID须为数字，不支持中文或字母)参数,若浏览器没有安装unity播放插件，请点击下载unity播放插件按钮</div>';
   // var html = '<div id="note">';
    html += '<div><form id="downUnityWebPlayerFull" action="#" ><input type="hidden" value="UnityWebPlayerFull.exe" id="UnityWebPlayerFull" name="UnityWebPlayerFull"/><input type="submit" onclick="downUnityWebPlayerFull();" class="btn btn-primary" value="下载unity播放插件"/></form><div></div>';
    html += "<div style='height: 160px;'></div>";
    $("#left").append(html);
}

var checkXML=false;

//cll 点击编辑
$("#editTechInfoBtn").click(function(){
	if($("#nodeid").val()==null || $("#nodeid").val()==undefined || $("#nodeid").val()=="" ){
		alert(i18n("i18n-alert-partNumber"))
	}else{
		$("#left").addClass("hide");
		$("#editTechInfo").modal('show');
	}

});

//cll 关闭编辑弹框按钮
$(".wrngdatas_edit_close").click(function(){
	$("#left").removeClass("hide");
	$("#editTechInfo").modal('hide');
});

